package com.liser.print.bluetooth;

import android.app.Application;
import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter;

import com.liser.print.bluetooth.receiver.BluReceiver;

/**
 * 蓝牙连接监听器
 *
 * @author Administrator
 * @date 2020/1/13 10:35
 */
public class BluetoothMonitor {

    private static BluReceiver bluReceiver;

    public static void init(Application application) {
        bluReceiver = new BluReceiver();
        IntentFilter intentFilter = new IntentFilter();
        // 监视蓝牙设备与APP连接的状态
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
        intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        // 注册广播
        application.registerReceiver(bluReceiver, intentFilter);
    }

    public static void remove(Application application) {
        application.unregisterReceiver(bluReceiver);
    }
}
